package com.shibida.shibidaProject.userInfo.dao;

import com.shibida.shibidaProject.userInfo.domain.CookerDetailVO;
import com.shibida.shibidaProject.userInfo.domain.UserVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CookerRepository extends JpaRepository<CookerDetailVO, Integer> {
    /**
     * 获取所有信息
     * @return
     */
    @Query(value = "select * from t_cooker where id=:id", nativeQuery = true)
    List<CookerDetailVO> queryAllById(int id);

    /**
     * 通过id获取当前用户的价格表
     * @param id
     * @return
     */
    @Query(value = "select * from t_cooker where id=:id", nativeQuery = true)
    List<CookerDetailVO> queryPriceById(int id);

    /**
     * 更新厨师信息
     * @param dishName  厨师的菜名
     * @param dishPrice 厨师菜名对应的价格
     * @param id  当前需要修该的厨师
     */
    @Transactional
    @Modifying
    @Query(value = "UPDATE `t_cooker` SET `dish` = :dishName, `price` = :dishPrice WHERE id = :id", nativeQuery = true)
    void updateNameAndPriceById(String dishName, String dishPrice, int id);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO `t_cooker` (`id`,`dish`,`price`,`score`,`service_number`,`food_show1`,`food_show2`, `food_show3`, `food_show4`) VALUES (:id,:dish,:price,:score,:service_number,:food_show1,:food_show2,:food_show3,:food_show4)", nativeQuery = true)
    void insertDish(int id, String dish, String price, float score, int service_number, String food_show1, String food_show2, String food_show3, String food_show4);
}
